import { Injectable } from '@angular/core';
import {GlobalAjaxService} from '../../services/global-ajax.service';
import {Subscription} from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class ArticleService {

  constructor(
    private gas: GlobalAjaxService
  ) {}

  /**
   * @description 创建博客
   */
  public uploadArticleCover(data, success, failed): Subscription {
    return this.gas.request({
      type: 'post',
      url: '/admin/articles/uploads/cover',
      data, success, failed
    });
  }

  /**
   * @description 创建博客
   */
  public createArticle(data, success, failed): void {
    this.gas.request({
      type: 'post',
      url: '/admin/articles/create',
      data, success, failed
    });
  }

  /**
   * @description 创建博客
   */
  public updateArticle(data, success, failed): void {
    this.gas.request({
      type: 'post',
      url: '/admin/articles/update',
      data, success, failed
    });
  }

  /**
   * @description 创建博客
   * @data { userId: number }
   */
  public readArticles(data, success, failed): void {
    this.gas.request({
      type: 'post',
      url: '/admin/articles/read',
      data, success, failed
    });
  }

  /**
   * @description 获取最新发表的文章
   * @data { }
   */
  public getLastCreate(data, success, failed): void {
    this.gas.request({
      type: 'post',
      url: '/admin/articles/lastCreate',
      data, success, failed
    });
  }

  /**
   * @description 获取最新发表的文章
   * @data { id: string }
   */
  public deleteArticleById(data, success, failed): void {
    this.gas.request({
      type: 'post',
      url: '/admin/articles/delete',
      data, success, failed
    });
  }

  /**
   * @description 获取文章详情
   */
  public getArticleDetail(data, success, failed): void {
    this.gas.request({
      type: 'get',
      url: '/admin/articles/articleDetail',
      data, success, failed
    });
  }
}
